package com.yc.web.controller;

import com.yc.services.OSSService;
import com.yc.web.controller.model.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/oss")
public class FileUploudController {
    @Autowired
    protected OSSService ossService;

    @PostMapping("/upload")
    @Operation(
            summary = "图片上传",
            description = "上传图片数组"
    )
    public ResponseResult uploadFile(
            @Parameter(
                    description = "图片文件数组",
                    content = @Content(mediaType = "multipart/form-data",
                            array = @ArraySchema(  // 关键：使用array表示数组
                                    schema = @Schema(type = "string", format = "binary")
                            )
                    )
            )
            @RequestPart("files") MultipartFile[] files
    ) {
        return ResponseResult.ok().setData(ossService.uploadFiles(files));
    }
}
